import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { AjaxResult } from '@/api/model';
import { PageRequest, PageData } from '@/utils/common/types';
import {
  KanbanInputDto,
  KanbanOutputDto,
  KanbanOutputDtoSimple,
  KanbanSetRoleDto,
  KanbanSetUserDto,
} from './model';
import { UserNode } from '@/api/identity/admin/user/model';
import { RoleNode } from '@/api/identity/admin/role/model';

/** 报表看板模块URL枚举 */
enum Api {
  /** 读取看板报表简单信息 */
  ReadSimple = '/api/report/admin/kanban/readSimple',
  /** 读取看板报表 */
  Read = '/api/report/admin/kanban/read',
  /** 创建看板报表 */
  Create = '/api/report/admin/kanban/create',
  /** 更新看板报表 */
  Update = '/api/report/admin/kanban/update',
  /** 删除看板报表 */
  Delete = '/api/report/admin/kanban/delete',

  /** 读取看板报表[角色]树 */
  ReadRoles = '/api/report/admin/kanban/readRoles',
  /** 读取看板报表[用户]树 */
  ReadUsers = '/api/report/admin/kanban/readUsers',

  /** 设置看板报表角色 */
  SetRoles = '/api/report/admin/kanban/setRoles',
  /** 设置看板报表用户 */
  SetUsers = '/api/report/admin/kanban/setUsers',
}

//#region 读取看板报表简单信息
/**
 * 读取看板报表简单信息
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function readKanbanSimple(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<KanbanOutputDtoSimple>>(
    {
      url: Api.ReadSimple,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 读取看板报表
/**
 * 读取看板报表
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function readKanban(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<KanbanOutputDto>>(
    {
      url: Api.Read,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 创建看板报表
/**
 * 创建看板报表
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function createKanban(dtos: KanbanInputDto[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Create,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 更新看板报表
/**
 * 更新看板报表
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function updateKanban(dtos: KanbanInputDto[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Update,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 删除看板报表
/**
 * 删除看板报表
 * @param ids 看板报表编号
 * @param mode 错误消息模型
 */
export function deleteKanban(ids: (string | bigint)[], mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.Delete,
      params: ids,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion

//#region 读取看板报表[角色]树
/**
 * 读取看板报表[角色]树
 * @param kanbanId 看板编号
 * @param mode 错误消息模型
 */
export function readKanbanRoles(kanbanId: string | bigint, mode: ErrorMessageMode = 'message') {
  return httpClient.get<RoleNode[]>(
    {
      url: Api.ReadRoles,
      params: { kanbanId: kanbanId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 读取看板报表[用户]树数据
/**
 * 读取看板报表[用户]树数据
 * @param kanbanId 看板编号
 * @param mode 错误消息模型
 */
export function readKanbanUsers(kanbanId: string | bigint, mode: ErrorMessageMode = 'message') {
  return httpClient.get<UserNode[]>(
    {
      url: Api.ReadUsers,
      params: { kanbanId: kanbanId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion

//#region 设置看板报表角色
/**
 * 设置看板报表角色
 * @param dtos 看板角色信息
 * @param mode 错误消息模型
 */
export function setKanbanRoles(dtos: KanbanSetRoleDto, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.SetRoles,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 设置看板报表用户
/**
 * 设置看板报表用户
 * @param dtos 看板用户信息
 * @param mode 错误消息模型
 */
export function setKanbanUsers(dtos: KanbanSetUserDto, mode: ErrorMessageMode = 'message') {
  return httpClient.post<AjaxResult>(
    {
      url: Api.SetUsers,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
